package com.hiray.viewtouchevent;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    ScrollView scrollView;
    LinearLayout linearLayout;
    View scrollItem1;

    ScrollViewEx scrollViewEx;
    View view1;
    View view2;
    View view3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        scrollView = findViewById(R.id.scroll_view);
        linearLayout = findViewById(R.id.linear_layout);
        scrollItem1 = findViewById(R.id.scroll_item1);

        scrollViewEx = findViewById(R.id.scroll_view_ex);
        view1 = findViewById(R.id.view1);
        view2 = findViewById(R.id.view2);
        view3 = findViewById(R.id.view3);
        addViewIntoScrollView();
    }

    private void addViewIntoScrollView() {
        for (int i = 0; i < 20; i++) {
            TextView textView = new TextView(this);
            textView.setText("ScrollItem" + (i + 2));
            textView.setBackgroundResource(i % 2 == 0 ? R.color.colorAccent : R.color.colorPrimary);
            textView.setWidth(200);
            textView.setHeight(200 + i * 10);
            textView.setAllCaps(false);
            linearLayout.addView(textView);
        }
    }

    public void _getScrollY(View view) {
        Log.i(TAG, "_getScrollY: " + scrollView.getScrollY() + "---" + scrollView.getHeight() + "---" + linearLayout.getBottom());
    }

    public void scrollTest(View view) {
        startActivity(new Intent(this, ScrollTestActivity.class));
    }

    public void VerticalExtentOfViews(View view) {
        Log.i(TAG, "VerticalExtentOfViews: " + (view1.getMeasuredHeight() + view1.getMeasuredHeight()+ view3.getMeasuredHeight()+scrollViewEx.getMeasuredHeight()));
        ;
    }
}
